package tv.acgn.advertisement.publish.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import tv.acgn.advertisement.publish.exception.AbstractAdPubException;
import tv.acgn.advertisement.publish.po.AdUnitPO;
import tv.acgn.advertisement.publish.service.AdUnitService;
import tv.acgn.advertisement.publish.vo.adunit.AdUnitRequestVO;
import tv.acgn.advertisement.publish.vo.adunit.AdUnitResponseVO;

/**
 * @author : junG
 * @program : advertisement-ad-pub-action
 * @description : 推广单元分发器
 * @date : 2019-06-02 14:23
 **/

@RestController
public class AdUnitAction {

    @Autowired
    private AdUnitService adUnitService;

    @GetMapping("/unit/{id}")
    public AdUnitPO get(@PathVariable(value = "id") String id) throws AbstractAdPubException {
        return adUnitService.getAdUnit(id);
    }

    @PostMapping(value = "/unit")
    public AdUnitResponseVO add(@RequestBody AdUnitRequestVO requestVO) throws AbstractAdPubException {
        return adUnitService.addAdUnit(requestVO);
    }

    @PutMapping(value = "/unit")
    public AdUnitResponseVO update(@RequestBody AdUnitRequestVO requestVO) throws AbstractAdPubException {
        return adUnitService.updateAdUnit(requestVO);
    }

    @DeleteMapping("/unit/{id}")
    public AdUnitResponseVO delete(@PathVariable(value = "id") String id) throws AbstractAdPubException {
        return adUnitService.deleteAdUnit(id);
    }
}
